<template>
	<view class="mask" @click.stop="maskClick" v-if="maskShow" @touchmove.stop.prevent="clear">
		<view class="dialog fadelogIn" @click.stop="clear" :class="top?'top':''" :style="{'background-color':bgcolors?bgcolors:'#fff','width':width}"  v-if="bodyShow">
			<view class="dialogTitle" :style="{'background-color':titlebg?titlebg:'#fff','color':titlebg?'#fff':'black'}" v-if="title">
				{{title}}
			</view>
			<view class="dialogbody "  @click.stop="clear">
				<slot></slot>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name:"mymodal",
		props: {
			width: {
				type: String,
				default: '96vw'
			},
			maskCloseAble:{type:Boolean,default:true},
			title: {
				type: String,
				default: undefined
			},
			bgcolors: {
				type: String
			},
			titlebg:{
				type:String
			},
			top:{
				type:Boolean,
				default:false
			}
		},
		
		
		data() {
			return {
				maskShow: false,
				bodyShow: false
			};
		},
		
		
		methods: {
			maskClick(){
				if(this.maskCloseAble){
					this.close()
				}
			},
			clear(e) {
				// TODO nvue 取消冒泡
				e.stopPropagation()
			},
			close() {
				this.maskShow = false
				this.bodyShow = false
				this.$emit("close")
			},
			open() {
				let that = this
				this.maskShow = true
				setTimeout(() => {
					that.bodyShow = true
				}, 200)
			}
		}
	}
</script>

<style lang="scss">
	.mask {
		width: 100vw;
		height: 100vh;
		background-color: rgba(53, 53, 53, .6);
		position: fixed;
		top: 0;
		left: 0;
		z-index: 500;
		display: flex;
		justify-content: center;
		align-items: center;
		.top{
			position: absolute;
			top: 20vh;
		}
		.dialog {
			border-radius: 8px;
			width: 700rpx;
			-webkit-box-shadow: 3px 3px 3px 3px #666666;
			box-shadow: 3px 3px 3px 3px #666666;
			background-color: white;
			z-index: 9999;
		}

		.dialogTitle {
			height: 5vh;
			line-height: 5vh;
			text-align: center;
			border-top-left-radius: 8px;
			border-top-right-radius: 8px;
			font-size: 26rpx;
		}

		.dialogbody {
			width: 100%;
		}
	}
</style>
